package zengjin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import zengjin.mapper.ImageMapper;
import zengjin.model.en.Image;
import zengjin.service.ImageService;

import java.io.File;

/**
* @author 19324
* @description 针对表【image】的数据库操作Service实现
* @createDate 2025-01-02 15:28:56
*/
@Service
@Slf4j
public class ImageServiceImpl extends ServiceImpl<ImageMapper, Image>
    implements ImageService {

    @Value("${uploadLocation.path-image}")
    private String uploadPath;

    @Override
    public boolean delete(String name) {
        File file = new File(uploadPath + name);
        log.info("删除文件：" + name);
        if (file.exists()) {
            file.delete();
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteImageList(String[] names) {
        //删除文件
        for (String name : names) {
            File file = new File(uploadPath + name);
            if (file.exists()) {
                file.delete();
            }
        }
        return true;
    }


}




